<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qquickrectangle.cpp -->
  <title>Rectangle QML 类型 | Qt Quick 5.12.3</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.12</a></td><td ><a href="qtquick-index.html">Qt Quick 模块</a></td><td ><a href="qtquick-qmlmodule.html">QML类型</a></td><td >Rectangle QML 类型</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtquick-index.html">Qt 5.12.3 参考指南</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">目录</a></h3>
<ul>
<li class="level1"><a href="#properties">属性</a></li>
<li class="level1"><a href="#details">详细信息</a></li>
<li class="level2"><a href="#appearance">Appearance</a></li>
<li class="level2"><a href="#example-usage">示例用法</a></li>
<li class="level2"><a href="#performance">Performance</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Rectangle QML 类型</h1>
<span class="subtitle"></span>
<!-- $$$Rectangle-brief -->
<p>Paints a filled rectangle with an optional border. <a href="#details">更多...</a></p>
<!-- @@@Rectangle -->
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> 导入语句：</td><td class="memItemRight bottomAlign"> import QtQuick 2.12</td></tr><tr><td class="memItemLeft rightAlign topAlign">继承自：</td><td class="memItemRight bottomAlign"> <p><a href="qml-qtquick-item.html">Item</a></p>
</td></tr></table></div><ul>
<li><a href="qml-qtquick-rectangle-members.html">所有成员的列表，包括继承成员</a></li>
</ul>
<a name="properties"></a>
<h2 id="properties">属性</h2>
<ul>
<li class="fn"><b><b><a href="qml-qtquick-rectangle.html#antialiasing-prop">antialiasing</a></b></b> : bool</li>
<li class="fn"><b><b><a href="qml-qtquick-rectangle.html#border-prop">border</a></b></b><ul>
<li class="fn"><b><b><a href="qml-qtquick-rectangle.html#border.width-prop">border.width</a></b></b> : int</li>
<li class="fn"><b><b><a href="qml-qtquick-rectangle.html#border.color-prop">border.color</a></b></b> : color</li>
</ul>
</li>
<li class="fn"><b><b><a href="qml-qtquick-rectangle.html#color-prop">color</a></b></b> : color</li>
<li class="fn"><b><b><a href="qml-qtquick-rectangle.html#gradient-prop">gradient</a></b></b> : any</li>
<li class="fn"><b><b><a href="qml-qtquick-rectangle.html#radius-prop">radius</a></b></b> : real</li>
</ul>
<!-- $$$Rectangle-description -->
<a name="details"></a>
<h2 id="details">详细信息</h2>
<p>Rectangle items are used to fill areas with solid color or gradients, and/or to provide a rectangular border.</p>
<a name="appearance"></a>
<h2 id="appearance">Appearance</h2>
<p>Each Rectangle item is painted using either a solid fill color, specified using the <a href="qml-qtquick-rectangle.html#color-prop">color</a> property, or a gradient, defined using a Gradient type and set using the <a href="qml-qtquick-rectangle.html#gradient-prop">gradient</a> property. If both a color and a gradient are specified, the gradient is used.</p>
<p>You can add an optional border to a rectangle with its own color and thickness by setting the <a href="qml-qtquick-rectangle.html#border.color-prop">border.color</a> and <a href="qml-qtquick-rectangle.html#border.width-prop">border.width</a> properties. Set the color to &quot;transparent&quot; to paint a border without a fill color.</p>
<p>You can also create rounded rectangles using the <a href="qml-qtquick-rectangle.html#radius-prop">radius</a> property. Since this introduces curved edges to the corners of a rectangle, it may be appropriate to set the <a href="qml-qtquick-item.html#antialiasing-prop">Item::antialiasing</a> property to improve its appearance.</p>
<a name="example-usage"></a>
<h2 id="example-usage">示例用法</h2>
<div class="float-right"><p><img src="images/declarative-rect.png" alt="" /></p>
</div><p>The following example shows the effects of some of the common properties on a Rectangle item, which in this case is used to create a square:</p>
<pre class="qml">

  import QtQuick 2.0

  <span class="type"><a href="qml-qtquick-rectangle.html">Rectangle</a></span> {
      <span class="name">width</span>: <span class="number">100</span>
      <span class="name">height</span>: <span class="number">100</span>
      <span class="name">color</span>: <span class="string">&quot;red&quot;</span>
      <span class="name">border</span>.color: <span class="string">&quot;black&quot;</span>
      <span class="name">border</span>.width: <span class="number">5</span>
      <span class="name">radius</span>: <span class="number">10</span>
  }

</pre>
<br style="clear: both" /><a name="performance"></a>
<h2 id="performance">Performance</h2>
<p>Using the <a href="qml-qtquick-item.html#antialiasing-prop">Item::antialiasing</a> property improves the appearance of a rounded rectangle at the cost of rendering performance. You should consider unsetting this property for rectangles in motion, and only set it when they are stationary.</p>
<p><b>请参考 </b><a href="qml-qtquick-image.html">Image</a>。</p>
<!-- @@@Rectangle -->
<h2>属性文档</h2>
<!-- $$$antialiasing -->
<div class="qmlitem"><div class="qmlproto">
<div class="table"><table class="qmlname">
<tr valign="top" class="odd" id="antialiasing-prop">
<td class="tblQmlPropNode"><p>
<a name="antialiasing-prop"></a><span class="name">antialiasing</span> : <span class="type"><a href="../qtqml/qml-bool.html">bool</a></span></p></td></tr>
</table></div>
</div><div class="qmldoc"><p>Used to decide if the Rectangle should use antialiasing or not. <a href="qtquick-visualcanvas-scenegraph-renderer.html#antialiasing">Antialiasing</a> provides information on the performance implications of this property.</p>
<p>The default is true for Rectangles with a radius, and false otherwise.</p>
</div></div><!-- @@@antialiasing -->
<br/>
<!-- $$$border -->
<div class="qmlitem"><div class="qmlproto"><div class="table"><table class="qmlname"><tr valign="top" class="even" id="border-prop"><th class="centerAlign"><p><a name="border-prop"></a><b>border group</b></p></th></tr><tr valign="top" class="odd" id="border.width-prop"><td class="tblQmlPropNode"><p><a name="border.width-prop"></a><span class="name">border.width</span> : <span class="type"><a href="../qtqml/qml-int.html">int</a></span></p></td></tr><tr valign="top" class="odd" id="border.color-prop"><td class="tblQmlPropNode"><p><a name="border.color-prop"></a><span class="name">border.color</span> : <span class="type"><a href="qml-color.html">color</a></span></p></td></tr></table></div></div><div class="qmldoc"><p>The width and color used to draw the border of the rectangle.</p>
<p>A width of 1 creates a thin line. For no line, use a width of 0 or a transparent color.</p>
<p><b>Note: </b>The width of the rectangle's border does not affect the geometry of the rectangle itself or its position relative to other items if anchors are used.</p><p>The border is rendered within the rectangle's boundaries.</p>
</div></div><!-- @@@border -->
<br/>
<!-- $$$color -->
<div class="qmlitem"><div class="qmlproto">
<div class="table"><table class="qmlname">
<tr valign="top" class="odd" id="color-prop">
<td class="tblQmlPropNode"><p>
<a name="color-prop"></a><span class="name">color</span> : <span class="type"><a href="qml-color.html">color</a></span></p></td></tr>
</table></div>
</div><div class="qmldoc"><p>This property holds the color used to fill the rectangle.</p>
<p>The default color is white.</p>
<div class="float-right"><p><img src="images/rect-color.png" alt="" /></p>
</div><p>The following example shows rectangles with colors specified using hexadecimal and named color notation:</p>
<pre class="qml">

  <span class="type"><a href="qml-qtquick-rectangle.html">Rectangle</a></span> {
      <span class="name">color</span>: <span class="string">&quot;#00B000&quot;</span>
      <span class="name">width</span>: <span class="number">80</span>; <span class="name">height</span>: <span class="number">80</span>
  }

  <span class="type"><a href="qml-qtquick-rectangle.html">Rectangle</a></span> {
      <span class="name">color</span>: <span class="string">&quot;steelblue&quot;</span>
      <span class="name">y</span>: <span class="number">100</span>; <span class="name">width</span>: <span class="number">80</span>; <span class="name">height</span>: <span class="number">80</span>
  }

</pre>
<br style="clear: both" /><p>If both a gradient and a color are specified, the gradient will be used.</p>
<p><b>请参考 </b><a href="qml-qtquick-rectangle.html#gradient-prop">gradient</a>。</p>
</div></div><!-- @@@color -->
<br/>
<!-- $$$gradient -->
<div class="qmlitem"><div class="qmlproto">
<div class="table"><table class="qmlname">
<tr valign="top" class="odd" id="gradient-prop">
<td class="tblQmlPropNode"><p>
<a name="gradient-prop"></a><span class="name">gradient</span> : <span class="type">any</span></p></td></tr>
</table></div>
</div><div class="qmldoc"><p>The gradient to use to fill the rectangle.</p>
<p>This property allows for the construction of simple vertical or horizontal gradients. Other gradients may be formed by adding rotation to the rectangle.</p>
<div class="float-left"><p><img src="images/declarative-rect_gradient.png" alt="" /></p>
</div><pre class="qml">

  <span class="type"><a href="qml-qtquick-rectangle.html">Rectangle</a></span> {
      <span class="name">y</span>: <span class="number">0</span>; <span class="name">width</span>: <span class="number">80</span>; <span class="name">height</span>: <span class="number">80</span>
      <span class="name">color</span>: <span class="string">&quot;lightsteelblue&quot;</span>
  }

  <span class="type"><a href="qml-qtquick-rectangle.html">Rectangle</a></span> {
      <span class="name">y</span>: <span class="number">100</span>; <span class="name">width</span>: <span class="number">80</span>; <span class="name">height</span>: <span class="number">80</span>
      <span class="name">gradient</span>: <span class="name">Gradient</span> {
          <span class="type"><a href="qml-qtquick-gradientstop.html">GradientStop</a></span> { <span class="name">position</span>: <span class="number">0.0</span>; <span class="name">color</span>: <span class="string">&quot;lightsteelblue&quot;</span> }
          <span class="type"><a href="qml-qtquick-gradientstop.html">GradientStop</a></span> { <span class="name">position</span>: <span class="number">1.0</span>; <span class="name">color</span>: <span class="string">&quot;blue&quot;</span> }
      }
  }

  <span class="type"><a href="qml-qtquick-rectangle.html">Rectangle</a></span> {
      <span class="name">y</span>: <span class="number">200</span>; <span class="name">width</span>: <span class="number">80</span>; <span class="name">height</span>: <span class="number">80</span>
      <span class="name">rotation</span>: <span class="number">90</span>
      <span class="name">gradient</span>: <span class="name">Gradient</span> {
          <span class="type"><a href="qml-qtquick-gradientstop.html">GradientStop</a></span> { <span class="name">position</span>: <span class="number">0.0</span>; <span class="name">color</span>: <span class="string">&quot;lightsteelblue&quot;</span> }
          <span class="type"><a href="qml-qtquick-gradientstop.html">GradientStop</a></span> { <span class="name">position</span>: <span class="number">1.0</span>; <span class="name">color</span>: <span class="string">&quot;blue&quot;</span> }
      }
  }

</pre>
<br style="clear: both" /><p>The property also accepts gradient presets from <a href="../qtgui/qgradient.html#Preset-enum">QGradient::Preset</a>. Note however that due to Rectangle only supporting simple vertical or horizontal gradients, any preset with an unsupported angle will revert to the closest representation.</p>
<pre class="qml">

  <span class="type"><a href="qml-qtquick-rectangle.html">Rectangle</a></span> {
      <span class="name">y</span>: <span class="number">0</span>; <span class="name">width</span>: <span class="number">80</span>; <span class="name">height</span>: <span class="number">80</span>
      <span class="name">gradient</span>: <span class="name">Gradient</span>.<span class="name">NightFade</span>
  }

  <span class="type"><a href="qml-qtquick-rectangle.html">Rectangle</a></span> {
      <span class="name">y</span>: <span class="number">0</span>; <span class="name">width</span>: <span class="number">80</span>; <span class="name">height</span>: <span class="number">80</span>
      <span class="name">gradient</span>: <span class="string">&quot;NightFade&quot;</span>
  }

</pre>
<br style="clear: both" /><p>If both a gradient and a color are specified, the gradient will be used.</p>
<p><b>请参考 </b><a href="qml-qtquick-gradient.html">Gradient</a> 和 <a href="qml-qtquick-rectangle.html#color-prop">color</a>。</p>
</div></div><!-- @@@gradient -->
<br/>
<!-- $$$radius -->
<div class="qmlitem"><div class="qmlproto">
<div class="table"><table class="qmlname">
<tr valign="top" class="odd" id="radius-prop">
<td class="tblQmlPropNode"><p>
<a name="radius-prop"></a><span class="name">radius</span> : <span class="type"><a href="../qtqml/qml-real.html">real</a></span></p></td></tr>
</table></div>
</div><div class="qmldoc"><p>This property holds the corner radius used to draw a rounded rectangle.</p>
<p>If radius is non-zero, the rectangle will be painted as a rounded rectangle, otherwise it will be painted as a normal rectangle. The same radius is used by all 4 corners; there is currently no way to specify different radii for different corners.</p>
</div></div><!-- @@@radius -->
<br/>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
